package cn.com.qiter.vod.controller;

import cn.com.qiter.common.Result;
import cn.com.qiter.servicebase.exceptionhandler.GuliException;
import cn.com.qiter.vod.Utils.ConstantVodUtils;
import cn.com.qiter.vod.Utils.InitVodCilent;
import cn.com.qiter.vod.service.VodService;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.vod.model.v20170321.DeleteVideoRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/eduvod/video")
@CrossOrigin
public class WxMiniController {

    @Autowired
    private VodService vodService;

    //上传视频到阿里云
    @PostMapping("uploadWxminiVideo")
    public Result uploadWxminiVideo(MultipartFile file) {
        //返回上传视频id
        String videoId = vodService.uploadVideoAly(file);
        return Result.ok().data("videoId",videoId);
    }

    @PostMapping("uploadWxVideo")
    public Result uploadWxVideo(HttpServletRequest request) {
        CommonsMultipartResolver mr = new CommonsMultipartResolver(request.getSession().getServletContext());
        String videoId = "";
        //检查form中是否有enctype="multipart/form-data"
        if (mr.isMultipart(request)){
            MultipartHttpServletRequest req = (MultipartHttpServletRequest) request;

            MultipartFile multipartFile = req.getFile("tempVideoPath");
            //返回上传视频id
            videoId = vodService.uploadVideoAly(multipartFile);
            String openId = req.getParameter("openid");
            String tempVideoPath = req.getParameter("tempVideoPath");
            String tempThumbPath = req.getParameter("tempThumbPath");
            String upload = req.getParameter("upload");
            String json = req.getParameter("json");

        }

        return Result.ok().data("videoId",videoId);
    }
}
